package com.luoran.kaka.config;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

	private static final Logger log = LoggerFactory.getLogger(WebMvcConfig.class);

//	@Bean
	public HandlerExceptionResolver customerExceptionPage() {
		HandlerExceptionResolver exceptionResolver = new HandlerExceptionResolver() {
			public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response,
					Object handler, Exception ex) {
				ModelAndView mav = new ModelAndView("/error-500");
				log.error(ex.getMessage(), ex.fillInStackTrace());
				mav.addObject("errorMsg", ex.toString());
				return mav;
			}
		};
		return exceptionResolver;
	}

}
